const person1 = {
  firstName: "John",
  lastName: "Doe",
  age: 50,
  eyeColor: "blue",
};

const person2 = { firstName: "Anne", lastName: "Smith" };

// 将源数据合并到目标数据上
Object.assign(person1, person2);
console.log(person1);

Object.assign(person1, [123, 2323]);
console.log(person1);

// 返回对象中键值对的数组
let text = Object.entries(person1);
console.log(text);

const fruits = [
  ["apples", 300],
  ["pears", 900],
  ["bananas", 500],
];

// 与 entries 相反，从键值对数组创建对象
const myObj = Object.fromEntries(fruits);
console.log(myObj);

// 获取对象中所有值
const values = Object.values(person1);
console.log(values);

const fruits2 = [
  { name: "apples", quantity: 300 },
  { name: "bananas", quantity: 500 },
  { name: "oranges", quantity: 200 },
  { name: "kiwi", quantity: 150 },
];

// 根据回调函数对数组进行分组
const result = Object.groupBy(fruits2, (item) =>
  item.quantity > 200 ? "ok" : "low"
);
console.log(result);
